﻿using MiniFox.Resources;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MiniFox.Exceptions
{
    /// <summary>
    /// 
    /// </summary>
    public class ComponentBuildingException : Exception
    {
        string _contractType;
        string _componentName;
        object[] _args;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="contractType"></param>
        /// <param name="componentName"></param>
        /// <param name="args"></param>
        public ComponentBuildingException(string contractType, string componentName, params object[] args)
           : this(contractType, componentName, string.Format(CommonMessages.EXPTN_ComponentBuilding, contractType, componentName), args)
        {
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="contractType"></param>
        /// <param name="componentName"></param>
        /// <param name="innerException"></param>
        /// <param name="args"></param>
        public ComponentBuildingException(string contractType, string componentName, Exception innerException, params object[] args)
           : this(contractType, componentName, string.Format(CommonMessages.EXPTN_ComponentBuilding, contractType, componentName), innerException, args)
        {
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="contractType"></param>
        /// <param name="componentName"></param>
        /// <param name="message"></param>
        /// <param name="args"></param>
        public ComponentBuildingException(string contractType, string componentName, string message, params object[] args)
            : base(message)
        {
            _contractType = contractType;
            _componentName = componentName;
            _args = args;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="contractType"></param>
        /// <param name="componentName"></param>
        /// <param name="message"></param>
        /// <param name="innerException"></param>
        /// <param name="args"></param>
        public ComponentBuildingException(string contractType, string componentName, string message, Exception innerException, params object[] args)
            : base(message, innerException)
        {
            _contractType = contractType;
            _componentName = componentName;
            _args = args;
        }
        /// <summary>
        /// 
        /// </summary>
        public string ContractType
        {
            get { return _contractType; }
        }
        /// <summary>
        /// 
        /// </summary>
        public string ComponentName
        {
            get { return _componentName; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string[] Arguments
        {
            get
            {
                if (_args == null || _args.Length <= 0)
                    return null;
                List<string> args = new List<string>();
                foreach (object val in _args)
                {
                    args.Add(val.ToString());
                }
                return args.ToArray();
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public override string Message
        {
            get
            {
                if (string.IsNullOrWhiteSpace(base.Message))
                    return string.Format(CommonMessages.EXPTN_ComponentBuilding, this.ContractType, this.ComponentName);
                return base.Message;
            }
        }
    }
}
